package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.SysLoginlogs;
import com.ruoyi.system.service.ISysLoginlogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/loginlogs")
public class SysLoginlogsController extends BaseController {
    @Autowired
    private ISysLoginlogsService loginlogsService;
    @Autowired
    private RedisService redisService;
    @RequiresPermissions("system:loginlogs:list")
    @GetMapping("/list")
    public TableDataInfo list(SysLoginlogs loginlogs){
        startPage();
        List<SysLoginlogs> list = loginlogsService.selectLoginlogsList(loginlogs);
        return getDataTable(list);
    }
    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:loginlogs:export")
    public void export(HttpServletResponse response,SysLoginlogs loginlogs){
        List<SysLoginlogs> list = loginlogsService.selectLoginlogsList(loginlogs);
        ExcelUtil<SysLoginlogs> util = new ExcelUtil<SysLoginlogs>(SysLoginlogs.class);
        util.exportExcel(response,list,"登录日志");
    }
    @RequiresPermissions("system:loginlogs:remove")
    @Log(title = "登录日志",businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds){
        return toAjax(loginlogsService.deleteLoginlogsByIds(infoIds));
    }
    @RequiresPermissions("system:loginlogs:remove")
    @Log(title = "登录日志",businessType = BusinessType.DELETE)
    @DeleteMapping("/clean")
    public AjaxResult clean(){
        loginlogsService.cleanLoginlogs();
        return success();
    }
    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody SysLoginlogs loginlogs){
        return toAjax(loginlogsService.insertLoginlogs(loginlogs));
    }
}
